package com.ruoyi.project.member.privilegepackage.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.member.privilegepackage.domain.PrivilegePackage;
import com.ruoyi.project.member.privilegepackage.service.IPrivilegePackageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员特权Controller
 *
 * @author shixiangwen
 * @date 2020-03-11
 */
@Controller
@RequestMapping("/member/privilegepackage")
public class PrivilegePackageController extends BaseController {
    private String prefix = "member/privilegepackage";

    @Autowired
    private IPrivilegePackageService privilegePackageService;

    @RequiresPermissions("member:privilegepackage:view")
    @GetMapping()
    public String privilegepackage() {
        return prefix + "/privilegepackage";
    }

    /**
     * 查询会员特权列表
     */
    @RequiresPermissions("member:privilegepackage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PrivilegePackage privilegePackage) {
        startPage();
        List<PrivilegePackage> list = privilegePackageService.selectPrivilegePackageList(privilegePackage);
        return getDataTable(list);
    }

    /**
     * 导出会员特权列表
     */
    @RequiresPermissions("member:privilegepackage:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PrivilegePackage privilegePackage) {
        List<PrivilegePackage> list = privilegePackageService.selectPrivilegePackageList(privilegePackage);
        ExcelUtil<PrivilegePackage> util = new ExcelUtil<PrivilegePackage>(PrivilegePackage.class);
        return util.exportExcel(list, "privilegepackage");
    }

    /**
     * 新增会员特权
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存会员特权
     */
    @RequiresPermissions("member:privilegepackage:add")
    @Log(title = "会员特权", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PrivilegePackage privilegePackage) {
        return toAjax(privilegePackageService.insertPrivilegePackage(privilegePackage));
    }

    /**
     * 修改会员特权
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        PrivilegePackage privilegePackage = privilegePackageService.selectPrivilegePackageById(id);
        mmap.put("privilegePackage", privilegePackage);
        return prefix + "/edit";
    }

    /**
     * 修改保存会员特权
     */
    @RequiresPermissions("member:privilegepackage:edit")
    @Log(title = "会员特权", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PrivilegePackage privilegePackage) {
        return toAjax(privilegePackageService.updatePrivilegePackage(privilegePackage));
    }

    /**
     * 删除会员特权
     */
    @RequiresPermissions("member:privilegepackage:remove")
    @Log(title = "会员特权", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(privilegePackageService.deletePrivilegePackageByIds(ids));
    }
}
